package com.qf.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qf.entity.User;
import com.qf.mapper.LoginMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;

@RequestMapping("user")
@Api(tags = "用户登录")
public class LoginController {

    @Resource
    private LoginMapper loginMapper;

    @ApiOperation(value = "用户登录")
    @RequestMapping("login")
    public String login(String username, String password) {
        User user = loginMapper.selectOne(new LambdaQueryWrapper<User>()
                .eq(User::getUsername, username)
                .eq(User::getPassword, password)
        );
        if (user != null) {
            return "登录成功";
        }
        return "登录失败";
    }
    @GetMapping(value = "/user")
    public User getUser(){
        return new User(1,"i","3");
    }
    @ApiOperation("可以指定参数的API")
    @PostMapping("/param")
    public String hello2(@ApiParam("用户名") String name){
        return "hello" + name;
    }
}
